package com.terrace.core.constant;

import java.util.Properties;

import org.springframework.core.io.ClassPathResource;

import com.terrace.core.exception.UtilsConfigException;

/**
 * 配置文件--config/config.properties
 * 
 * @author jiangyg
 *
 */
public class ConfigConstant {

	private static final Properties UTILS_CONFIG_PROPERTIES = new Properties();
	
	/**
	 * 获取配置属性的值
	 * @param key
	 * @return
	 */
	public static String value(String key) {
		if (UTILS_CONFIG_PROPERTIES.isEmpty()) {
			synchronized (ConfigConstant.class) {
				if (UTILS_CONFIG_PROPERTIES.isEmpty()) {
					final String configPath = "config/config.properties";
					try {
						ClassPathResource resource = new ClassPathResource(configPath);
						UTILS_CONFIG_PROPERTIES.load(resource.getInputStream());
					} catch (Exception e) {
						throw new UtilsConfigException("未找到公共工具的[" + configPath + "]配置文件");
					}
				}
			}
		}
		return UTILS_CONFIG_PROPERTIES.getProperty(key);
	}
	
}
